/**
 * NetworkSystemsAPI.java
 * ************************** 
 * @date Apr 18, 2011
 * @author Michele Tamburini
 * 
 * **************************
 */
package systems.network;

import gossipServices.network.NetworkServicesAPI;

import infrastructureAPI.Service;

import java.net.InetAddress;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import messages.Message;

/**
 * Description: 
 * Similarly to the {@link NetworkServicesAPI} the NetworkSystemsAPI
 * provides a layer that all the system classes can use 
 * in order to get the access to the underlying network
 * and the communication with other nodes.
 *
 */
public interface NetworkSystemsAPI extends Service {
	
	/**
	 * Sends the {@link Message} 'msg' in input to its
	 * destination node.
	 * @param msg
	 * @return
	 */
	public boolean send(Message msg);
	
	/**
	 * Receives a {@link Message} from any sender.
	 * @return
	 */
	public Message receive();
	
	/**
	 * Contact the node specified by the InetAddress 'address', 
	 * try to retrieve the rmiregistry that is listening in the port
	 * 'port' and get the Remote object defined by the String 'service'.
	 * Then it deposit the Message 'msg' into the message box of that
	 * object.  
	 * Returns true in none error occurs.
	 * @param address : InetAddress
	 * @param port : Integer
	 * @param service : String
	 * @param msg : Message
	 * @return done : boolean
	 * @throws RemoteException
	 * @throws NotBoundException
	 */
	public boolean contactRemoteService(InetAddress address, Integer port, 
			String service, Message msg) throws RemoteException, NotBoundException;
	
	
}
